import 'package:common_utils/common_utils.dart';
import 'package:intl/intl.dart';

/// 格式化时间
String duTimeLineFormat(DateTime dt) {
  var now = DateTime.now();
  var difference = now.difference(dt);

  // 1天内
  if (difference.inHours < 24) {
    return "${difference.inHours} hours ago";
  }
  // 30天内
  else if (difference.inDays < 30) {
    return "${difference.inDays} days ago";
  }
  // MM-dd
  else if (difference.inDays < 365) {
    final dtFormat = new DateFormat('MM-dd');
    return dtFormat.format(dt);
  }
  // yyyy-MM-dd
  else {
    final dtFormat = new DateFormat('yyyy-MM-dd');
    var str = dtFormat.format(dt);
    return str;
  }
}

/*
  * go日期转换
  */
String formatDateStr(String data, {String format = 'yyyy-MM-dd'}) {
  if (data.isEmpty) {
    return data;
  }
  if (data == '0001-01-01T00:00:00Z') {
    return '';
  }
  return DateUtil.formatDateStr(data, format: format,isUtc: false);
}

///时间转换 将秒转换为小时分钟
String durationTransform(int seconds) {
  var d = Duration(seconds: seconds);
  List<String> parts = d.toString().split(':');
  return '${parts[0]}小时${parts[1]}分';
}
